package unq.tpi.persistencia.performanceEj.servicios;

import unq.tpi.persistencia.performanceEj.daos.DepartmentDAO;
import unq.tpi.persistencia.performanceEj.model.Department;
import unq.tpi.persistencia.performanceEj.model.Employee;

public class ListadoPagosPorDepto extends AbstractListado {

	private String num;
	private Department depto = null;

	public ListadoPagosPorDepto(String num) {
		this.num = num;
	}

	@Override
	protected void doListado() throws Exception {
		depto = new DepartmentDAO().getByCodeForListadoPagosPorDepto(num);		//Emanuel: no me anda, explota por falta de memoria
		//depto = new DepartmentDAO().getByCodeForListadoPagosPorDepto2(num);	//Emanuel: pasa en +/- 70 segs
		
		this.newLine();
		this.addColumn("Total").addColumn(depto.getTotalSalaries()).newLine();
		this.newLine();

		System.out.println("==================================");
		System.out.println("calculado salario total");
		System.out.println("==================================");
				
		this.addColumn("Nombre");
		this.addColumn("Titulo");
		this.addColumn("Monto");
		this.newLine();
		
		int index=1;
		int total=depto.getEmployees().size();

		for (Employee e : depto.getEmployees()) {
			this.addColumn(e.getFullName());
			this.addColumn(e.getTitle());
			this.addColumn(e.getSalary());
			this.newLine();
			System.out.println("procesado "+index+" empleado de "+total);
			index++;
		}
		
		System.out.println("==================================");
		System.out.println("detalle de empleados listo");
		System.out.println("==================================");
	}

	@Override
	public String getFilename() {
		return "./target/PagosPorDepto.csv";
	}
}
